<template>
	<view class="tabbar">
		<view class="child" v-for="(item,index) in tabbarList" :key="index" @tap="handleClick(item,index)">
			<image v-show="item.flag" :src="item.activeIconUrl" mode=""></image>
			<image v-show="!item.flag" :src="item.iconUrl" mode=""></image>
			<text :style="{color:item.flag?'#000':'#bfbfbf'}">
				{{item.text}}
			</text>
		</view>
	</view>
</template>

<script>
	export default {
		name: "tabbar",
		props: ["current"],
		data() {
			return {
				tabbarList: [{
					text: "书城",
					iconUrl: "/static/image/bookStore/bookstore.png",
					activeIconUrl: "/static/image/bookStore/bookstored.png",
					flag: false
				}, {
					text: "分类",
					iconUrl: "/static/image/bookStore/classify.png",
					activeIconUrl: "/static/image/bookStore/classifyd.png",
					flag: false
				}, {
					text: "书架",
					iconUrl: "/static/image/bookStore/bookshelf.png",
					activeIconUrl: "/static/image/bookStore/bookshelfd.png",
					flag: false
				}, {
					text: "我的",
					iconUrl: "/static/image/bookStore/myself.png",
					activeIconUrl: "/static/image/bookStore/myselfd.png",
					flag: false
				}]
			};
		},
		created() {
			this.tabbarList.forEach((item, index) => {
				if (index == this.current) {
					item.flag = true
				} else {
					item.flag = false
				}
			})
		},
		methods: {
			handleClick(item, index) {
				if (item.flag) {
					return
				}

				this.tabbarList.map((item) => item.flag = false)
				item.flag = true
				this.$emit("handelSelect", index)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.tabbar {
		position: relative;
		width: 100%;
		height: 120rpx;
		background-color: $global-background;
		// box-shadow: 0px -3rpx 4rpx 1px rgba(0, 0, 0, 0.04);
		border-radius: 0px 0px 0px 0px;
		opacity: 1;
		display: flex;
		justify-content: center;

		.child {
			width: 170rpx;
			height: 100%;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			font-size: 24rpx;
			font-weight: 400;
			image {
				width: 50rpx;
				height: 50rpx;
			}
		}
	}

	.tabbar::before {
		position: absolute;
		content: "";
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		box-shadow: 0px -3rpx 4rpx 1px rgba(0, 0, 0, 0.04);
	}
</style>